package com.yqd.lesson.actor.three

import akka.actor.SupervisorStrategy.{Decider, Escalate, Restart, Stop}
import akka.actor.{Actor, ActorContext, ActorInitializationException, ActorKilledException, ActorLogging, ActorRef, ChildRestartStats, DeathPactException, OneForOneStrategy, Props, SupervisorStrategy}


object Sender{
  def props:Props = Props[Sender]
}

class Sender extends Actor with ActorLogging{

  override def supervisorStrategy: SupervisorStrategy = OneForOneStrategy(){
    case _: ActorInitializationException => Stop
    case _: ActorKilledException         => Stop
    case _: DeathPactException           =>
      log.info("------Supervision DeathPactException------")
      Stop
    case _: NullPointerException =>{
      log.info("------Supervision NullPointerException------")
      Stop
    }
    case _: Exception                    =>
      log.info("------Supervision Exception------")
      Restart
  }

  override def receive: Receive = {
    case msg:String =>{
      val son = context.actorOf(Props[Receiver],"son1")
      son ! msg;
    }
    case msg:Int =>{
      val son = context.actorOf(Props[Receiver],"son2")
      son ! msg;
    }
  }

}
